﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Model.WaiGaoQiao;
using DAO.WaiGaoQiao;

namespace WaiGaoQiaoWeb.FilterSession
{
    /// <summary>
    /// 拦截器 在过程请求授权时调用
    /// </summary>
    public class AuthorizeAttribute : FilterAttribute, IAuthorizationFilter
    {
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            if (HttpContext.Current.Session["user"] == null)
            {
                //跳转到登录页面
                filterContext.HttpContext.Response.Redirect("/Account/LogOn");
                //filterContext.HttpContext.Response.Write(" <script language=\"javascript\">window.open(\"/Login/Login\", \"_top\", \"height=screen.height , width=screen.width,top=0, left=0, toolbar =yes, menubar=yes, scrollbars=yes, resizable=yes, location=yes, status=yes,fullscreen=yes \") </script>");
                filterContext.Result = new HttpUnauthorizedResult();//返回未授权Resultwindow.location='/Login/Login';   
            }
        }
    }
}